import Vue from 'vue'
import VueRouter from 'vue-router'

import Login from '@/views/Login'
import Layout from '@/views/Layout'
import Home from '@/views/Home'
import User from '@/views/User'
import search from '@/views/Search'
import SearchResult from '@/views/Search/SearchResult.vue'
import ArticleDetail from '@/views/Article/id.vue'
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/layout' // 重定向
  },
  {
    path: '/login',
    component: Login
  }, {
    path: '/layout',
    component: Layout,
    redirect: '/layout/home', // 重定向到首页
    // 二级路由（嵌套路由）
    children: [
      {
        path: 'home',
        component: Home
      }, {
        path: 'user',
        component: User
      }
    ]
  }, {
    path: '/search',
    component: search
  }, {
    path: '/SearchResult/:name',
    component: SearchResult
  }, {
    path: '/article',
    component: ArticleDetail
  }
]

const router = new VueRouter({
  routes
})

export default router
